package com.example.studentvotesystem.controller;

import com.example.studentvotesystem.entity.ScenicSpot;
import com.example.studentvotesystem.service.ScenicSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private ScenicSpotService scenicSpotService;

    @GetMapping("/index")
    public String index(Model model, HttpSession session) {
        List<ScenicSpot> spots = scenicSpotService.getAllSpotsWithVoteCount();
        model.addAttribute("spots", spots);
        return "index";
    }

    @GetMapping("/result")
    public String result(Model model) {
        List<ScenicSpot> spots = scenicSpotService.getAllSpotsWithVoteCount();
        model.addAttribute("spots", spots);
        return "result";
    }
}
